<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="support.*, java.util.*" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Provide Degrees - Choose Location</title>
</head>
<body>
	<h1>Provide Degrees</h1>
	<%
	student stu = (student)session.getAttribute("student");
	if(request.getParameter("moreDegrees") != null){
		out.println(stu.printAttributes());
	}
	else{
		
		String firstName = (String)stu.getAttribute("firstName");
	    String lastName = (String)stu.getAttribute("lastName");
		String middleName = (String)stu.getAttribute( "middleName" );
		String citizenship = (String)stu.getAttribute( "citizenship" );
		String residence = (String) stu.getAttribute( "residence" );
		
		out.println(firstName + " " + middleName + " " + lastName +"</br>");
		out.println("Country of Citizenship: " + citizenship + "</br>");
		out.println("Country of Residence: " + residence + "</br>");
		out.println("Address </br>");
		
		String resident = request.getParameter( "resident" );
		if(resident != null){
			stu.setAttribute("resident",resident);
			String street = (String)stu.getAttribute("street");
		    String city = (String)stu.getAttribute("city");
			String phone = (String)stu.getAttribute( "phone" );
			String phoneCode = (String)stu.getAttribute( "phoneCode" );
			out.println("Street: " + street + "</br>");
			out.println("City: " + city + "</br>");
			out.println("Phone: " + phone  + "</br>");
			out.println("Phone Code: " + phoneCode + "</br>");
			out.println("Resident: " + resident + "</br>");
		}
		else if(request.getParameter( "moreDegrees" ) == null){
			String street = request.getParameter( "street" );
			String city = request.getParameter( "city" );
			String state = request.getParameter( "state" );
			String zipCode = request.getParameter( "zipCode" );
			String phone = request.getParameter( "phone" );
			stu.setAttribute("street",street);
			stu.setAttribute("city",city);
			stu.setAttribute("state",state);
			stu.setAttribute("zipCode",zipCode);
			stu.setAttribute("phone",phone);
			out.println("Street: " + street + "</br>");
			out.println("City: " + city + "</br>");
			out.println("State: " + state + "</br>");
			out.println("Zip Code: " + zipCode + "</br>");
			out.println("Phone: " + phone  + "</br>");
		}
		
		
		
	}	
	
	session.setAttribute("student", stu);

	
%>	
	<h2>Choose Location</h2>
	
	<h3>Locations:</h3>
	
  	<%  
  		//If the DegreeContainer doesn't exist create a new one and add the first degree object
  		DegreeContainer degrees = (DegreeContainer)session.getAttribute("DegreeContainer");
  		if(degrees == null){
  			degrees = new DegreeContainer();
  			degrees.addDegree();
  			session.setAttribute("DegreeContainer", degrees);
  		}
  		
  		String moreDegrees = request.getParameter("moreDegrees");
  		if(moreDegrees != null && moreDegrees.equals("true")){
  			//Check to make sure that the last page we were on
  			//really was the moredegrees page
  			if(degrees.isMoreDegrees()){
  				//add another degree
  				degrees.addDegree();
  			}
  			
  			//Set it back to false
  			degrees.setIsMoreDegrees(false);
  			session.setAttribute("DegreeContainer", degrees);
  		}
  		
	   	support s = new support();   	
	   	
	   	String path2 = config.getServletContext().getRealPath("universities.txt");
	    Vector universities = s.getUniversities(path2);
	    
	    int size = universities.size();
	    int incr = size/3;
	  	int size1 = 0;
	  	int size2 = size1 + incr;
	  	int size3 = size2 + incr;
	  	int size4 = size;
    %>
	<table border="1">
			<td>
				<%    	
				    for (int i=size1; i<size2; i++){
				      //each entry in the universities vector is a tuple with the first entry being the country/state
				      //and the second entry being a vector of the universities as String's
				      Vector tuple = (Vector)universities.get(i);
				      String state = (String)tuple.get(0);
				      out.println("<a href=\'university.jsp?location=" + state + "\'>" + state + "</a><br>");
				    }
			    %>
			</td>
			<td>
				<%
				    //print all the countries
				    for(int i=size2; i<size3; i++){
				    	//each entry in the universities vector is a tuple with the first entry being the country/state
					      //and the second entry being a vector of the universities as String's
					      Vector tuple = (Vector)universities.get(i);
					      String state = (String)tuple.get(0);
					      out.println("<a href=\'university.jsp?location=" + state + "\'>" + state + "</a><br>");
				    }
				%>
			
			</td>
			<td>
				<%
				    //print all the countries
				    for(int i=size3; i<size4; i++){
				    	//each entry in the universities vector is a tuple with the first entry being the country/state
					      //and the second entry being a vector of the universities as String's
					      Vector tuple = (Vector)universities.get(i);
					      String state = (String)tuple.get(0);
					      out.println("<a href=\'university.jsp?location=" + state + "\'>" + state + "</a><br>");
				    }
				%>
			</td>
	</table> 
   
</body>
</html>